package com.situ.crm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.crm.common.ServerResponse;
import com.situ.crm.entity.CusDevPlan;
import com.situ.crm.entity.Customer;
import com.situ.crm.entity.Product;
import com.situ.crm.mapper.CusDevPlanMapper;
import com.situ.crm.mapper.CustomerMapper;
import com.situ.crm.mapper.ProductMapper;
import com.situ.crm.service.ICusDevPlanService;
import com.situ.crm.service.ICustomerService;
import com.situ.crm.service.IProductService;

@Service
public class CustomerServiceImpl implements ICustomerService {

	@Autowired
	private CustomerMapper customerMapper;

	@Override
	public ServerResponse selectCustomer() {
		List<Customer> list = customerMapper.selectCustomer();

		return ServerResponse.createSuccess("成功", list);
	}

	@Override
	public Integer selectCustomerId(Integer id) {
		Integer customerId = customerMapper.selectCustomerId(id);
		return customerId;
	}

	@Override
	public ServerResponse pageList(Integer page, Integer limit) {
		//分页
		PageHelper.startPage(page,limit);
		//查询
		List<Customer> list = customerMapper.selectCustomer();
		//优化
		PageInfo pageInfo = new PageInfo<>(list);
		Integer count = (int) pageInfo.getTotal();
		
		return ServerResponse.createSuccess("成功", count, list);
	}

	@Override
	public ServerResponse insert(Customer customer) {
		Integer count = customerMapper.insertSelective(customer);
		if (count ==1) {
			return ServerResponse.createSuccess("成功");
		} else {
			return ServerResponse.createSuccess("失败");
		}
	}

}
